package com.edgclub.edg.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.UserInfoOtherActivity;
import com.edgclub.edg.model.User;
import com.edgclub.edg.model.result.FindCartoonData;
import com.edgclub.edg.uc.UnableScrollGridView;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;
import com.edgclub.edg.utils.util.DensityUtils;

import java.util.ArrayList;

/**
 * 漫画大触
 */
public class FindCartoonStarAdapter extends BaseAdapter {
    private Context mContext;

    private ArrayList<FindCartoonData.CartoonStar> datas;

    private GlideUtils glideUtils;

    private ViewHolder holder;
    private int itemW;

    public FindCartoonStarAdapter(Context mContext) {
        this.mContext = mContext;
        glideUtils = new GlideUtils();
        itemW = (DensityUtils.getScreenW((Activity) mContext) - 33) / 2;
    }

    public ArrayList<FindCartoonData.CartoonStar> getDatas() {
        return datas;
    }

    public void setDatas(ArrayList<FindCartoonData.CartoonStar> datas) {
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_find_cartoon_star, null);
            holder = new ViewHolder();
            holder.unableScrollGridView = (UnableScrollGridView) convertView.findViewById(R.id.unableScrollGridView);
            holder.user_icon = (ImageView) convertView.findViewById(R.id.user_icon);
            holder.vip = (ImageView) convertView.findViewById(R.id.vip);
            holder.tv_mark = (TextView) convertView.findViewById(R.id.tv_mark);
            holder.user_name = (TextView) convertView.findViewById(R.id.user_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final FindCartoonData.CartoonStar cartoonStar = datas.get(position);
//        final User user1 = cartoonStar.getUser();
        final User user = cartoonStar.getUser();
        glideUtils.Glidde_loadCropCircleImage(mContext, user.getLogo(), holder.user_icon);
        holder.user_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, UserInfoOtherActivity.class);
                intent.putExtra("user",user);
                mContext.startActivity(intent);
            }
        });
        holder.tv_mark.setText(cartoonStar.getMark() + "");
        holder.user_name.setText(user.getNick() + "");
        holder.unableScrollGridView.setVisibility(View.GONE);
        if(cartoonStar.getPosts()!=null && cartoonStar.getPosts().size()>0){
            holder.unableScrollGridView.setVisibility(View.VISIBLE);
            FindCartoonStarAdapter2 gridViewAdapter = new FindCartoonStarAdapter2(mContext);
            gridViewAdapter.setDatas(cartoonStar.getPosts());
            holder.unableScrollGridView.setAdapter(gridViewAdapter);
            gridViewAdapter.notifyDataSetChanged();
        }
        if(null!=user.getUserAuth()){
            if ("-1".equals(user.getUserAuth().getType())){
                holder.vip.setVisibility(View.GONE);
            }
            if("0".equals(user.getUserAuth().getType())){
                holder.vip.setVisibility(View.VISIBLE);
                holder.vip.setImageResource(R.drawable.v_huan);
            }else if("1".equals(user.getUserAuth().getType())){
                holder.vip.setVisibility(View.VISIBLE);
                holder.vip.setImageResource(R.drawable.v_lan);
            }
        }else{
            holder.vip.setVisibility(View.GONE);
        }
        return convertView;
    }


    public class ViewHolder {

        public ImageView user_icon ,vip;
        public TextView tv_mark, user_name;
        private UnableScrollGridView unableScrollGridView;
    }


}
